package fashionshop.bll;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;

import fashionshop.dal.ImportDAL;
import fashionshop.dal.OrderDAL;

public class ImportBLL {

	private int id;
	private int staffId;
	private BigDecimal sum;
	private String createDate;
	private String note;
	
	public ImportBLL() {
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getStaffId() {
		return staffId;
	}
	public void setStaffId(int staffId) {
		this.staffId = staffId;
	}

	public BigDecimal getSum() {
		return sum;
	}
	public void setSum(BigDecimal sum) {
		this.sum = sum;
	}
	public String getCreateDate() {
		return createDate;
	}
	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}
	public String getNote() {
		return note;
	}
	public void setNote(String note) {
		this.note = note;
	}
	
	public static Vector loadAllImport() throws Exception {
		
		Vector importTableRecords = new Vector();
		ResultSet result = ImportDAL.LoadAll();
		while (result.next()){
			Vector record = new Vector();
            record.add(result.getInt("ID"));
            record.add(result.getString("Sum"));
            record.add(result.getString("CreateDate"));
            record.add(result.getString("Note"));
            
            importTableRecords.add(record);
		}
		return importTableRecords;
	}
	
	public boolean SaveAll(ImportBLL importBll) throws Exception {
		
//		boolean flag = true;
//		for(int i = 0 ; i < importTableRecords.size(); i++){
//			Vector vt = (Vector) importTableRecords.get(i);
//			// Only save the order that was updated
//			if(vt.get(4) != null){
//				if(vt.get(0).toString() == null || vt.get(0).toString().isEmpty() || vt.get(0).toString().equals("")){
//					ImportBLL importBll = new ImportBLL();
//					importBll.setSum(new BigDecimal(vt.get(1).equals("") ? "0" : vt.get(1).toString()));
//					importBll.setCreateDate(new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
//					importBll.setNote(vt.get(3).toString());
//					
//					if(ImportDAL.Insert(importBll) == 0){
//						flag = false;
//						break;
//					}
//					else{// Save success
//						
//					}
//				}
//				else{
//					ImportBLL importBll = new ImportBLL();
//					importBll.setId(Integer.parseInt(vt.get(0).toString()));
//					importBll.setSum(new BigDecimal(vt.get(1).equals("") ? "0" : vt.get(1).toString()));
//					importBll.setNote(vt.get(3).toString());
//					
//					if(ImportDAL.Update(importBll) == 0){
//						flag = false;
//						break;
//					}
//					else{ // Save success
//						
//					}
//				}
//			}
//		}
//			
//		return flag;
		
		if(ImportDAL.Insert(importBll) == 0)
			return false;
		return true;
		
	}
}
